import { createStore, applyMiddleware } from 'redux'
import thunk from 'redux-thunk'
import { getToken } from '@/utils'
// import { composeWithDevTools } from 'redux-devtools-extension'
import rootReducer from './reducers'
let middlewares
if (process.env.NODE_ENV === 'production') {
  // 生产环境，只启用 thunk 中间件
  middlewares = applyMiddleware(thunk)
} else {
  // 开发环境
  const { composeWithDevTools } = require('redux-devtools-extension')
  middlewares = composeWithDevTools(applyMiddleware(thunk))
}
// const middLewares = composeWithDevTools(applyMiddleware(thunk))
// const initialState = {
//   login: localStorage.getItem('geek-token'),
// }
const initialState = { login: getToken() }
const store = createStore(rootReducer, initialState, middlewares)
export default store
